# -*- coding: utf-8 -*
import os

import SingleFileInfo

# 文件整体合计, 统计所有文件的数量
from Enums import FileType


class FilesInfo:
    files = 0
    lines = 0
    code = 0
    comments = 0
    blanks = 0

    debug_code_str = []
    debug_comment_str = []

    # 累计单个文件信息
    def add(self, single_file_info: SingleFileInfo.SingleFileInfo):
        self.files += 1
        self.lines += single_file_info.line
        self.code += single_file_info.code
        self.comments += single_file_info.comment
        self.blanks += single_file_info.blank

        for s in single_file_info.test_comment_str:
            self.debug_comment_str.append(s)

        for s in single_file_info.test_code_str:
            self.debug_code_str.append(s)

    def save(self, file_type):
        if file_type == FileType.Ruby:
            type = '.rb'
        else:
            type = '.cpp'
        f = open('./code' + type, 'w')
        for s in self.debug_code_str:
            f.write(s)
            f.write('\n')
        f.close()

        f2 = open('./comments' + type, 'w')
        for s in self.debug_comment_str:
            f2.write(s)
            f2.write('\n')
        f2.close()
